﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using PloobsEngine;
using PloobsEngine.SceneControl;
using PloobsEngine.Utils;
using Etapa1.SofRender;
using System.Collections.Generic;
using ModelXML;
using PloobsEngine.Cameras;
using Etapa1.Import;

namespace Etapa1.Screens
{
    public class SoftScreen : IScreen
    {
        public SoftScreen()
            : base()
        {
        }

        Device device ;
        CameraStatic camera;
        SEffect bs;

        public override void LoadContent(EngineStuff es)
        {            
            base.LoadContent(es);

            device = new Device();

            TextureShader ts = new TextureShader();
            ts.Projection = Matrix.Identity;
            ts.View = Matrix.Identity;
            ts.World = Matrix.Identity;
            ts.Difuse = EngineStuff.CustomContentManager.GetAsset<Texture2D>("Textures//brick");

            BasicShader bbs = new BasicShader();
            bbs.Projection = Matrix.Identity;
            bbs.View = Matrix.Identity;
            bbs.World = Matrix.Identity;
            
            ///ts ou bbs
            bs = ts;
            
        }

        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            device.Clear(Color.Red, 1);

            VertexType v0 = new VertexType();
            VertexType v1 = new VertexType();
            VertexType v2 = new VertexType();
            VertexType v3 = new VertexType();
            VertexType v4 = new VertexType();
            VertexType v5 = new VertexType();

            v0[Slots.POSITION0] = new Vector4(-0.5f, -0.5f, 0, 1);
            v1[Slots.POSITION0] = new Vector4(0, 0.5f, 0, 1);
            v2[Slots.POSITION0] = new Vector4(0.5f, -0.5f, 0, 1); 
            v3[Slots.POSITION0] = new Vector4(0.5f, -0.5f, 0, 1);
            v4[Slots.POSITION0] = new Vector4(0, 0.5f, 0, 1);
            v5[Slots.POSITION0] = new Vector4(0.5f, 0.5f, 0, 1);

            v0[Slots.TEXTCOORD0] = new Vector4(0, 0, 0, 0);
            v1[Slots.TEXTCOORD0] = new Vector4(1, 0, 0, 0);
            v2[Slots.TEXTCOORD0] = new Vector4(0.5f, 0.5f, 0, 0);
            v3[Slots.TEXTCOORD0] = new Vector4(1, 0, 0, 0);
            v4[Slots.TEXTCOORD0] = new Vector4(0.5f, 0.5f, 0, 0);
            v5[Slots.TEXTCOORD0] = new Vector4(1, 1, 0, 0);

            v0[Slots.NORMAL0] = Color.Red.ToVector4();
            v1[Slots.NORMAL0] = Color.Green.ToVector4();
            v2[Slots.NORMAL0] = Color.Blue.ToVector4();
            v3[Slots.NORMAL0] = Color.Red.ToVector4();
            v4[Slots.NORMAL0] = Color.Green.ToVector4();
            v5[Slots.NORMAL0] = Color.Blue.ToVector4();

            v0[Slots.TEXTCOORD1] = Color.Red.ToVector4();
            v1[Slots.TEXTCOORD1] = Color.Green.ToVector4();
            v2[Slots.TEXTCOORD1] = Color.Blue.ToVector4();
            v3[Slots.TEXTCOORD1] = Color.Red.ToVector4();
            v4[Slots.TEXTCOORD1] = Color.Green.ToVector4();
            v5[Slots.TEXTCOORD1] = Color.Blue.ToVector4();

            VertexType[] triangle = new VertexType[] {v0,v1,v2,v3,v4,v5};
            
            device.SetEffect(bs);
            device.SetVertexBuffer(triangle);
            device.DrawPrimitive(PrimitivesType.TriangleList);
            
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }

        public override void Draw(GameTime gameTime)
        {
            device.Draw();
            base.Draw(gameTime);

        }
    }
        
}

